import os
import unittest
from Parser import *

class TestEnum(unittest.TestCase):
    def testBrief(self):
        content = '''
        enum A
        {
            a, b='b', c 
        };
        typedef enum {} B;
        '''
#       result = ParseString(content)
#       e = result[0]
#       self.assertEqual(e.name, 'A')
#       self.assertEqual(len(e.item_list), 3)
#       self.assertEqual(e.item_list[0], Enumerator('a'))
#       self.assertEqual(e.item_list[1], Enumerator('b', "'b'"))
#       self.assertEqual(e.item_list[2], Enumerator('c'))

#       e = result[1]
#       self.assertEqual(e.name, 'B')
#       self.assertEqual(len(e.item_list), 0)

class TestClass(unittest.TestCase):
    def testEmpty(self):
        result = ParseString('')
        self.assertEqual(len(result), 0)

#   def testBrief(self):
#       c = ParseString('typedef class {public:}A;')[0]
#       self.assertEqual(c.name, 'A')
#       self.assertEqual(c.parent_list, [])
#       self.assertEqual(c.member_list, [])
#       self.assertEqual(c.template_parameter_list, [])

#       c = ParseString('struct A:B{};')[0]
#       self.assertEqual(c.name, 'A')
#       self.assertEqual(c.parent_list, ['B'])
#       self.assertEqual(c.member_list, [])
#       self.assertEqual(c.template_parameter_list, [])

#       c = ParseString('struct A:B, //COMMENT \n C,D{};')[0]
#       self.assertEqual(c.name, 'A')
#       self.assertEqual(c.parent_list, ['B', 'C', 'D'])
#       self.assertEqual(c.member_list, [])
#       self.assertEqual(c.template_parameter_list, [])

#       c = ParseString('template<class T>\n\t class A {  \n};')[0]
#       self.assertEqual(c.name, 'A')
#       self.assertEqual(c.parent_list, [])
#       self.assertEqual(c.member_list, [])
#       self.assertEqual(c.template_parameter_list, ['T'])

    def testSimpleClass(self):
        content = '''
        struct A:B,
        /*
         * CD
         ***/
          C, /**/
          D
          {
              public :
              ;
              virtual const int a(const A*const p1, char, B & p2 = p3) const;
              inline const P b() = 0;
              auto double v;
              static const int p1= 2E9, *const p2, &p3 = 2.e-10f,*p4[2][3LU];

              private:
              ~A();
          };
        '''
#       c = ParseString(content)[0]
#       self.assertEqual(c.name, 'A')
#       self.assertEqual(c.parent_list, ['B', 'C', 'D'])
#       self.assertEqual(c.template_parameter_list, [])
#       self.assertEqual(len(c.member_list), 7)

#       f = c.member_list[0]
#       self.assertEqual(f.virtual, True)
#       self.assertEqual(f.const, True)
#       self.assertEqual(f.name, 'a')
#       self.assertEqual(f.pure, False)
#       self.assertEqual(f.return_type.const, True)
#       self.assertEqual(f.return_type.type, 'int')
#       self.assertEqual(f.return_type.name, '')
#       
#       v = f.parameter_list[0]
#       self.assertEqual(v.const, True)
#       self.assertEqual(v.name, 'p1')
#       self.assertEqual(v.type, 'A')
#       self.assertEqual(v.reference, False)
#       self.assertEqual(v.pointer, True)
#       self.assertEqual(v.const_pointer, True)
#       self.assertEqual(v.default_value, '')
#       
#       v = f.parameter_list[1]
#       self.assertEqual(v.const, False)
#       self.assertEqual(v.name, '')
#       self.assertEqual(v.type, 'char')
#       self.assertEqual(v.reference, False)
#       self.assertEqual(v.pointer, False)
#       self.assertEqual(v.const_pointer, False)
#       self.assertEqual(v.default_value, '')
#       
#       v = f.parameter_list[2]
#       self.assertEqual(v.const, False)
#       self.assertEqual(v.name, 'p2')
#       self.assertEqual(v.type, 'B')
#       self.assertEqual(v.reference, True)
#       self.assertEqual(v.pointer, False)
#       self.assertEqual(v.const_pointer, False)
#       self.assertEqual(v.default_value, 'p3')
#       
#       f = c.member_list[1]
#       self.assertEqual(f.virtual, False)
#       self.assertEqual(f.const, False)
#       self.assertEqual(f.name, 'b')
#       self.assertEqual(f.pure, True)
#       self.assertEqual(f.return_type.const, True)
#       self.assertEqual(f.return_type.type, 'P')
#       self.assertEqual(f.return_type.name, '')

#       v = c.member_list[2]
#       self.assertEqual(v.const, False)
#       self.assertEqual(v.name, 'v')
#       self.assertEqual(v.type, 'double')

#       v = c.member_list[3]
#       self.assertEqual(v.const, True)
#       self.assertEqual(v.name, 'p1')
#       self.assertEqual(v.type, 'int')
#       self.assertEqual(v.reference, False)
#       self.assertEqual(v.pointer, False)
#       self.assertEqual(v.const_pointer, False)
#       self.assertEqual(v.default_value, '2E9')

#       v = c.member_list[4]
#       self.assertEqual(v.const, True)
#       self.assertEqual(v.name, 'p2')
#       self.assertEqual(v.type, 'int')
#       self.assertEqual(v.reference, False)
#       self.assertEqual(v.pointer, True)
#       self.assertEqual(v.const_pointer, True)

#       v = c.member_list[5]
#       self.assertEqual(v.const, True)
#       self.assertEqual(v.name, 'p3')
#       self.assertEqual(v.type, 'int')
#       self.assertEqual(v.reference, True)
#       self.assertEqual(v.pointer, False)
#       self.assertEqual(v.const_pointer, False)
#       self.assertEqual(v.default_value, '2.e-10f')

#       v = c.member_list[6]
#       self.assertEqual(v.const, True)
#       self.assertEqual(v.name, 'p4[2][3LU]')
#       self.assertEqual(v.type, 'int')
#       self.assertEqual(v.reference, False)
#       self.assertEqual(v.pointer, True)
#       self.assertEqual(v.const_pointer, False)

class TestFile(unittest.TestCase):
    def testBrief(self):
        content = '''
        typedef enum {a,b} A;
        struct B {};
        int C = 0U;
        '''
        result = ParseString(content)
        self.assertEqual(len(result), 3)
        self.assertTrue(isinstance(result[0], EnumStruct))
        self.assertTrue(isinstance(result[1], ClassStruct))

if __name__ == '__main__':
    unittest.main()

